<!-- from 7 5 2 7 1 8 9 2 0 -->
<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('defaultTranslate.operator')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select allowClear :placeholder="$t('inPrint.selectPerson')" style="width: 200px" v-model="queryParam.creator">
                <a-select-option v-for="(item,index) in userList" :key="index" :value="item.id">
                {{ item.userName }}
                  </a-select-option>
                </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('reportQuery.documentDate')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-range-picker
                    style="width: 100%"
                    v-model="queryParam.createTimeRange"
                    :default-value="defaultTimeStr"
                    format="YYYY-MM-DD"
                    :placeholder="[$t('reportQuery.startTime'), $t('reportQuery.endTime')]"
                    @change="onDateChange"
                  />
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons table-operator">
                  <a-button type="primary" @click="searchQuery">{{$t('reportQuery.query')}}</a-button>
                  <ColumnsSetting style="ma" @columnsChange="columnsChange" :columns="columns"></ColumnsSetting>
                  <a-button v-if="btnEnableList.indexOf(5) > -1"  style="margin-left: 8px" @click="reportPrint" icon="printer">{{$t('reportQuery.print')}}</a-button>                 
                  <a-button v-if="btnEnableList.indexOf(5) > -1"  style="margin-left: 8px" @click="generatePrintData" icon="printer">{{$t('inPrint.other') + $t('reportQuery.print')}}</a-button>
                  <a-button v-if="btnEnableList.indexOf(3) > -1" :loading="downLoading" style="margin-left: 8px" @click="exportExcel" icon="download">{{$t('reportQuery.export')}}</a-button>
                </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <!-- table区域-begin -->
        <section ref="print" id="reportPrint">
          <a-table
            bordered
            ref="table"
            size="middle"
            rowKey="id"
            :columns="columns"
            :customRow="rowClick"
            :dataSource="dataSource"
            :pagination="false"
            :loading="loading"
            @change="handleTableChange">
            <span slot="inSum" slot-scope="text, record">
              <a @click="myHandleDetail(record,1)" style="color:#409eff">{{ record.inSum }}</a>
            </span>
            <span slot="outSum" slot-scope="text, record">
              <a @click="myHandleDetail(record,2)" style="color:#409eff">{{ record.outSum }}</a>
            </span>
          </a-table>
          <a-row :gutter="24" style="margin-top: 8px;text-align:right;">
            <a-col :md="24" :sm="24">
              <a-pagination @change="paginationChange" @showSizeChange="paginationShowSizeChange"
                size="small"
                show-size-changer
                :showQuickJumper="true"
                :current="ipagination.current"
                :page-size="ipagination.pageSize"
                :page-size-options="ipagination.pageSizeOptions"
                :total="ipagination.total"
                :show-total="(total, range) => $t('reportQuery.common') +`${total-Math.ceil(total/ipagination.pageSize)}`+ $t('reportQuery.strip')">
                <template slot="buildOptionText" slot-scope="props">
                  <span>{{ props.value-1 }}{{$t('reportQuery.strip')}}/{{$t('reportQuery.page')}}</span>
                </template>
              </a-pagination>
            </a-col>
          </a-row>
        </section>
        <!-- table区域-end -->
        <EmployeeReportModual ref="EmployeeReportModual" @ok="modalFormOk"></EmployeeReportModual>

      </a-card>
    </a-col>
    <saleOutRepotModual ref="saleOutRepotModual" :list="dataSource" :columns="columns" :queryParam="queryParam"></saleOutRepotModual>
  </a-row>
</template>
<script>
  import EmployeeReportModual from './modules/EmployeeReportModual'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getNowFormatYear, getMpListShort, openDownloadDialog, sheet2blob} from "@/utils/util"
  import { getUserList } from '@/api/api'
  import JEllipsis from '@/components/jeecg/JEllipsis'
  import moment from 'moment'
  import Vue from 'vue'
  import saleOutRepotModual from './modules/saleOutRepotModual';
  export default {
    name: "EmployeeReport",
    mixins:[JeecgListMixin],
    components: {
      JEllipsis,
      EmployeeReportModual,
      saleOutRepotModual
    },
    data () {
      return {
        labelCol: {
          span: 5
        },
        wrapperCol: {
          span: 18,
          offset: 1
        },
        queryParam: {
          beginTime: getNowFormatYear() + '-01-01',
          endTime: moment().format('YYYY-MM-DD'),
          creator:undefined,
          userId:undefined
        },
        ipagination:{
          pageSize: 11,
          pageSizeOptions: ['11', '21', '31', '101', '201']
        },
        dateFormat: 'YYYY-MM-DD',
        currentDay: moment().format('YYYY-MM-DD'),
        defaultTimeStr: '',
        tabKey: "1",
        userList:[],
        // 表头
        columns: [
          {
            title: this.$t('defaultTranslate.lineNumber'), dataIndex: 'rowIndex',  align:"center",
            customRender:function (t,r,index) {
              return (t !== '合计') ? (parseInt(index) + 1) : t
            }
          },
          {title:this.$t('otherJS.userName'), dataIndex: 'loginName', },
          {title:this.$t('otherJS.saleAmount'), dataIndex: 'discountLastMoney', ellipsis:true},
          {title:this.$t('otherJS.discountAmount'), dataIndex: 'discountAllPrice', ellipsis:true},
          {title:this.$t('reportQuery.returnAmount'), dataIndex: 'salesReturnPrice', ellipsis:true},
          // {title:this.$t('reportQuery.extendedInformation'), dataIndex: 'materialOther', width: 150, ellipsis:true},
          {title:this.$t('reportQuery.taxAmount'), dataIndex: 'taxMoney', ellipsis:true},
          {title:this.$t('otherJS.salesTotal'), dataIndex: 'allPrice', ellipsis:true},
        ],
        url: {
          list: "/depotHead/findPromotionCreatorCount"
        }
      }
    },
    created () {
      this.defaultTimeStr = [moment(getNowFormatYear() + '-01-01', this.dateFormat), moment(this.currentDay, this.dateFormat)]
      this.initUser()
    },
    methods: {
      moment,
      getQueryParams() {
        this.queryParam.creator = this.queryParam.creator || ''
        let param = Object.assign({}, this.queryParam);
        param.currentPage = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize-1;
        return param;
      },
      onDateChange: function (value, dateString) {
        console.log(dateString[0],dateString[1]);
        this.queryParam.beginTime=dateString[0];
        this.queryParam.endTime=dateString[1];
      },
      searchQuery() {
        if(this.queryParam.beginTime == '' || this.queryParam.endTime == ''){
          this.$message.warning(this.$t('reportQuery.pleaseDate'))
        } else {
          this.loadData(1);
        }
      },
      rowClick(record, index) {
        return {
          on: {
            dblclick: (event) => {
              this.$refs.EmployeeReportModual.show(record,this.queryParam,this.btnEnableList)
            },
          }
        }
      },
    myHandleDetail(record,type){
      this.$refs.materialInOutList.setUrl('/depotItem/findDetailByMaterialId')
      if(type == 1){
        this.showReportFlowList(record, this.$t('purchasingManagement.receiptStock'),1)
            }else if(type == 2){
              this.showReportFlowList(record, this.$t('purchasingManagement.purchaseReturn'),2)
            }            
    },
    showReportFlowList(record,title,type){
        this.$refs.materialInOutList.reportShow(record, this.queryParam,type);
        this.$refs.materialInOutList.title = title;
        this.$refs.materialInOutList.disableSubmit = false;
    },
    showMaterialInOutList(record) {
        let depotIds = ''
        if(this.depotSelected && this.depotSelected.length>0) {
          depotIds = this.depotSelected.join()
        }
        this.$refs.materialInOutList.show(record, depotIds);
        this.$refs.materialInOutList.title = this.$t('reportQuery.viewFlow');
        this.$refs.materialInOutList.disableSubmit = false;
      },
      
      initUser () {
        getUserList({}).then((res) => {
          this.userList = res
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>